package com.atguigu.tingshu.user.api;

import com.alibaba.fastjson.JSONObject;
import com.atguigu.tingshu.common.login.GuiguLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.user.service.UserListenProcessService;
import com.atguigu.tingshu.vo.user.UserListenProcessVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

@Tag(name = "用户声音播放进度管理接口")
@RestController
@RequestMapping("api/user/userListenProcess")
@SuppressWarnings({"unchecked", "rawtypes"})
public class UserListenProcessApiController {

	@Autowired
	private UserListenProcessService userListenProcessService;
	///api/user/userListenProcess/getLatelyTrack
	@GuiguLogin
	@Operation(summary = "查询最近一次的播放记录")
	@GetMapping("getLatelyTrack")
	public Result getLatelyTrack(){
		JSONObject jsonObject = userListenProcessService.getLatelyTrack();
		return Result.ok(jsonObject);
	}
	///api/user/userListenProcess/updateListenProcess
	@Operation(summary = "更新播放进度")
	@GuiguLogin
	@PostMapping("updateListenProcess")
	public Result updateListenProcess(@RequestBody UserListenProcessVo vo){
		userListenProcessService.updateListenProcess(vo);
		return Result.ok();
	}


	///api/user/userListenProcess/getTrackBreakSecond/3636
	//1、整合mongodb：依赖+配置文件
	//2、为mongodb的集合创建实体类：UserListenProcess
	@Operation(summary = "查询声音的播放进度")
	@GuiguLogin
	@GetMapping("getTrackBreakSecond/{trackId}")
	public Result getTrackBreakSecond(@PathVariable("trackId")Long trackId){
		BigDecimal breakSecond = userListenProcessService.getTrackBreakSecond(trackId);
		return Result.ok(breakSecond);
	}

}

